package com.river.springbootdemo.thinkingjava.objectrefer;

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;

public class PriorityQueueDemo {
    public static void main(String[] args) {
        PriorityQueue<Double> priorityQueue = new PriorityQueue<>();
        Random random = new Random(47);
        for (int i = 0; i < 10; i++) {
            priorityQueue.offer(random.nextDouble());
        }
        PriorityQueue<Object> objQueue = new PriorityQueue<>();
        objQueue.offer(12.0);
        objQueue.offer(new String("12"));
        printQueue(priorityQueue);
//        不能在同一queue中加入不同类型数据
        printObjQueue(objQueue);
    }

    public static void printObjQueue(Queue<Object> queue) {
        Object o;
        while ((o = queue.poll()) != null) {
            System.out.print(o);
        }
    }

    public static void printQueue(Queue<Double> queue) {
        Double d;
        while ((d = queue.poll()) != null) {
            System.out.print(d + " ");
        }
    }
}
